#include <iostream>
using namespace std;
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <string>

#include <vector>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv)
{
	int n;
	cin >> n;
	vector<string> s(n);

	vector<int> ret(n);
	

	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	for (int i = 0; i < n; i++)
	{
		vector<int> hashA(26);
		vector<int> hasha(26);
		vector<int> hashn(10);
		vector<int> hasht(2);
		int flag = 0;
		int m = s[i].size();
		int tmp = 0;
		int num = 0, a = 0, t = 0;
		for (int j = 0; j < m; j++)
		{
			if (s[i][j] <= 'z' && s[i][j] >= 'a')
			{
				a = 1;
				tmp = s[i][j] - 'a';
				hasha[tmp] ++;
				if (hasha[tmp] > 2)
				{
					flag++;
				}
			}
			else if (s[i][j] <= 'Z' && s[i][j] >= 'A')
			{
				a = 1;
				tmp = s[i][j] - 'A';
				hashA[tmp]++;
				if (hashA[tmp] > 2)
				{
					flag++;
				}
			}
			else if (s[i][j] <= '9' && s[i][j] >= '0')
			{
				num = 1;
				tmp = s[i][j] - '0';
				hashn[tmp]++;
				if (hashn[tmp] > 2)
				{
					flag++;
				}
			}
			else
			{
				t = 1;
				if (s[i][j] == '*')
				{
					hasht[0]++;
				}
				else
				{
					hasht[1]++;
				}
				if (hasht[0] > 2 || hasht[1] > 2)
				{
					flag++;
				}
			}
		}
		if (!num || !a || !t)
		{
			ret[i] = 0;
		}
		else if (flag)
		{
			ret[i] = 1;
		}
		else
		{
			ret[i] = 2;
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout << ret[i] << endl;
	}
	return 0;
}










//int main()
//{
//    priority_queue<int,vector<int>, greater<int>> pq;
//
//    pq.push(5);
//    pq.push(2);
//    pq.push(8);
//
//    int highestPriority = pq.top();
//    cout << "The highest priority element is: " << highestPriority << endl;
//
//    pq.pop();
//
//    highestPriority = pq.top();
//    cout << "The new highest priority element is: " << highestPriority << endl;
//
//
//    return 0;
//}


//int main()
//{
//	auto p1 = make_pair(1, "wei");
//	set<int> s = { 1,2, 3, 4, 5 };
//	set<int>::iterator it = s.begin();
//	while (it != s.end())
//	{
//		cout << *it << " ";
//		it++;
//	}
//	cout << endl;
//	for (auto e : s)
//	{
//		cout << e << " ";
//	}
//	return 0;
//}


//int main()
//{
//	//map<string, int> m = { {"yueji",2},{"meigui",1} };
//	//for (const auto& e : m)
//	//{
//	//	cout << e.first << ":" << e.second << endl;
//	//}
//	//string s = "weisihao";
//	//reverse(s.begin(), s.end());
//	//cout << s;
//	//string s;
//	//cin >> s;
//	//cout << s << endl;
//	//string s1;
//	//getline(cin, s1);
//	//cout << s1 << endl;
//	string s2 = "weisihao";
//	int found = s2.find("wei");
//	string s3 = s2.substr(3,5);
//	string s4 = to_string(1234);
//	cout << s4;
//	return 0;
//}


